package com.gelsanalyzer.core;

import java.awt.event.*;

import javax.swing.*;

import org.apache.log4j.*;

import com.gelsanalyzer.mvc.controller.*;
import com.gelsanalyzer.ui.swing.command.*;

public class ActionFactory {
    private static final Logger log = Logger.getLogger(ActionFactory.class);

    private static IController controller;
    private static Action addCourseAction;
    private static Action saveAction;
    private static Action exitAction;
    private static Action courseNumsAction;
    private static Action courseEntryItemCommand;
    private static Action removeCourseAction;
    private static Action optimizeCourseAction;
    private static Action viewDepartmentsReportAction;
    private static Action viewGoalReportAction;

    // make sure we have a singleton...
    private ActionFactory() {
        log.info("Constructing the ActionFactory Singleton instance");
    };

    public static Action getAddCourse() {
        log.info("In the getAddCourse() method");
        if ( addCourseAction == null ) {
            addCourseAction = new AddCourseCommand("Add Course", null,
                "This will add your currently selected course.", KeyEvent.VK_A,
                controller);
            addCourseAction.setEnabled(false);
        }
        return addCourseAction;
    }

    public static Action getOptimizeCourse() {
        log.info("In the getOptimizeCourse() method");
        if ( optimizeCourseAction == null ) {
            optimizeCourseAction = new OptimizeCourseCommand("Optimize Course",
                null, "This will optimize your currently selected courses.",
                KeyEvent.VK_O, controller);
            // TODO: change back to false when done testing...
            optimizeCourseAction.setEnabled(true);
        }
        return optimizeCourseAction;
    }

    public static Action getRemoveCourse() {
        log.info("In the getRemoveCourse() method");
        if ( removeCourseAction == null ) {
            removeCourseAction = new RemoveCourseCommand("Remove Course", null,
                "This will remove your currently selected course.",
                KeyEvent.VK_R, controller);
            removeCourseAction.setEnabled(false);
        }
        return removeCourseAction;
    }

    public static Action getSaveAction() {
        log.info("In the getSaveAction() method");
        if ( saveAction == null ) {
            saveAction = new SaveCommand("Save", null,
                "This will save your current progress.", KeyEvent.VK_S,
                controller);
        }
        return saveAction;
    }

    public static Action getExitAction() {
        log.info("In the getExitAction() method");
        if ( exitAction == null ) {
            exitAction = new ExitCommand("Exit", null,
                "This will exit the application.", KeyEvent.VK_F4, controller);
        }
        return exitAction;
    }

    public static void setMasterController(IController safc) {
        controller = safc;
    }

    public static Action getCourseNums() {
        log.info("In the getCourseNums() method");
        if ( courseNumsAction == null ) {
            courseNumsAction = new GetCoursesCommand("Get Courses", null, null,
                null, controller);
        }
        return courseNumsAction;
    }

    public static Action getGetCourseEntryItemCommand() {
        log.info("in the getGetCourseEntryItemCommand() method");
        if ( courseEntryItemCommand == null ) {
            courseEntryItemCommand = new GetCourseEntryItemCommand(
                "Course Selected", null, null, null, controller);
        }
        return courseEntryItemCommand;
    }

    public static Action getViewDepartmentsReport() {
        log.info("in the getViewDepartmentsReport() method");
        if ( viewDepartmentsReportAction == null ) {
            viewDepartmentsReportAction = new ViewDepartmentsReportCommand(
                "View by Departments", null, null, null, controller);
        }
        return viewDepartmentsReportAction;

    }

    public static Action getViewGoalReport() {
       log.info("in the getViewGoalReport() method");
        if ( viewGoalReportAction == null ) {
            viewGoalReportAction = new ViewGoalReportCommand(
                "View by Goals", null, null, null, controller);
        }
        return viewGoalReportAction;
    }
}
